//渲染
function rander(data){
    $('.row').remove();
    data.forEach(item => {
        let html = 
            `  
            <tr class="row">
            <td>${item.id}</td>
            <td>${item.tite}</td>
            <td>${item.imports}</td>
            <td>${item.text}</td>
            <td>${item.cat}</td>
            <td>${item.atou}</td>
            <td>${item.time}</td>
           <td><input type="button" value="编辑" onclick="endit(${item.id})">
           <input type="button" value="删除" onclick="del(${item.id})"></td>

        </tr>
            
            `
         $('#data_table').append(html);   
    });
//斑马纹
    let rows = $('.row')
    for (let i = 0; i < rows.length; i++) {
        if(i%2==0){
            rows[i].style.background = 'rgb(200,220,230)'
        }else{
            rows[i].style.background = 'rgb(170,200,200)'
        }
        
    }

}
//显示数据
$(function (){
    getbloglist().then(data=>{
        rander(data)
    })
})

//查找
function query(){
    let keyword = $('[name=keyword]').val();
    getbloglist(keyword).then(data=>{
        rander(data)
    })
}
//删除
function del(id){
    let f= "是否删除"
    if(confirm(f)){
        delblog(id).then(data=>{
        rander(data)
    })
    }
}
//编辑
function endit(id){
    window.location.href=`addOrendit.html?${id}`
}
//新增
function add(){
    window.location.href=`addOrendit.html`
}